//
//  CustomView.m
//  响应者对象
//
//  Created by 伍银荣 on 2021/7/5.
//  Copyright © 2021 com.WYR. All rights reserved.
//

#import "CustomView.h"

@implementation CustomView

//触摸的四种方法

//手指接触到这个view的时候调用
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesBegan--%@",touches);
    UITouch *t = touches.anyObject;
//    //触摸对象所在的window
//    NSLog(@"window = %@",t.window);
//    //主窗口
//    NSLog(@"keyWindow = %@", [UIApplication sharedApplication].keyWindow);
//    //当前view所在的window
//    NSLog(@"---window = %@",self.window);
//    //触摸的view
//    NSLog(@"view = %@",t.view);
//    //当前view
//    NSLog(@"---view = %@",self);
//    //快速点击的次数
//    NSLog(@"tapCount = %ld",t.tapCount);
    
    //当前点击view的位置
    CGPoint currentPoint = [t locationInView:t.view];
    //上一次点击view的位置
    CGPoint lastPoint = [t previousLocationInView:t.view];
    NSLog(@"currentPoint = %@",NSStringFromCGPoint(currentPoint));
    NSLog(@"lastPoint = %@",NSStringFromCGPoint(lastPoint));
    //可以发现:当前触摸的上一点等于上一点触摸的当前点
    
}

//手指在这个view移动的时候调用
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesMoved");
}

//手指离开这个view的时候调用
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesEnded");
}

//意外中断(在点击view的同时,突然有电话打了进来)
-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesCancelled");
}





/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
